package com.yc.fruitmarket.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.fruitmarket.biz.addrBiz;
import com.yc.fruitmarket.biz.impl.addrBizImpl;

@WebServlet("/addrController/*")
public class addrController extends BaseServlet {
	private addrBiz ab = new addrBizImpl();
	
	public void openL(HttpServletRequest req, HttpServletResponse resp) {
		String aid = req.getParameter("aid");
	}
	
	public void getaddrs(HttpServletRequest req, HttpServletResponse resp) {
		String uid = req.getParameter("uid");
		if("".equals(uid) || uid == null) {
			return;
		}
		List<Map<String, String>> list = ab.getaddrs(uid);
		if(list.size() > 0) {
			this.send(resp, list);
		}else {
			return;
		}
	}
	
	public void addAddr(HttpServletRequest req, HttpServletResponse resp) {
		String uid = req.getParameter("uid");
		String aname = req.getParameter("aname");
		String atel = req.getParameter("atel");
		String prov = req.getParameter("prov");
		String city = req.getParameter("city");
		String area = req.getParameter("area");
		String address = req.getParameter("address");
		int result = ab.addAddr(uid, aname, atel, prov, city, area, address);
		if(result > 0) {
			this.send(resp, result);
		}else {
			this.send(resp, -1);
		}
		
	}
	
	public void apiAddr(HttpServletRequest req, HttpServletResponse resp) {
		Map<String,String> map = (Map<String, String>) req.getSession().getAttribute("userInfo");
		String uid = map.get("uid");
		String aname = map.get("uname");
		String atel = map.get("tel");
		String prov = req.getParameter("province");
		String city = req.getParameter("city");
		String area = req.getParameter("area");
		String address = req.getParameter("address");
		int result = ab.addAddr(uid, aname, atel, prov, city, area, address);
		if(result > 0) {
			this.send(resp, result);
		}else {
			this.send(resp, -1);
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
